package com.atguigu.day07.test;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/6 9:38
 * @注释 1、拼接字符和字符串
 *      2、寻找最大公约数
 */
public class VariableArgsExer {
    public static String joint(char a, String... b) {
        String s = "";
        for (int i = 0; i < b.length; i++) {
            if (i == 0) {
                s += b[i];
            } else {
                s += (a + b[i]);
            }
        }
        return s;
    }

    public static int commonDivisor(int... a) {
        int min = a[0];
        for (int i = 0; i < a.length; i++) {
            if (a[i] < min) {
                min = a[i];
            }
        }
        l:
        for (int i = min; i >= 1; i--) {
            for (int j : a) {
                if (j % i != 0) {
                    continue l;
                }
            }
            return i;
        }
        return 1;
    }

    public static void main(String[] args) {

        System.out.println("最大公约数是：" + commonDivisor(3,6,9,12,18));

        System.out.println(joint('-', "ab", "cd", "ef", "ghi", "jkl", "mno", "pqr", "tuv", "wxyz"));
    }
}
